﻿using Microsoft.EntityFrameworkCore;
using MyBlog.Model.Models;
using System;

namespace MyBlog.Repository
{
    public class BlogDBContext:DbContext
    {
        public BlogDBContext(DbContextOptions<BlogDBContext> options) : base(options)
        {

        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>().HasData(
                new User
                {
                    Id = 1,
                    Name = "chongzi",
                    NickName="虫子不吃鸟",
                    Password="123456",
                    Email = "18829206496@163.com",
                    Phone= "18829206496"
                }
            );

            //设置联合主键(主要针对多对多中间表)
            modelBuilder.Entity<UserBlog>().HasKey(x => new { x.UserId, x.BlogId });
        }

        public DbSet<User> Users { get; set; }
        public DbSet<Blog> Blogs { get; set; }
        public DbSet<BlogType> BlogTypes { get; set; }
        public DbSet<UserBlog> UserBlog { get; set; }
        public DbSet<UserBlogInfo> UserBlogInfos { get; set; }
    }
}
